const TITLE = "New VQ"; // 网页标题
const VERSION = '0.12.80'; // 网页版本
const ParentUrl = window.location.protocol+"//"+window.location.host;

const VQClientUrl = "https://s01.lanzoug.com:446/06031000105130390bb/2023/03/08/153beac8e3377680e9f6b47bf15ca1e4.zip?st=7PUNnC2bvZRHDvGcn5ZS0A&e=1685762848&b=VFAPXgU1UHtXMlUtC2gGLFJ9XWhUJQ_c_c&fi=105130390&pid=113-201-200-254&up=2&mp=0&co=1";
const HeadImgUrl = "https://i41.lanzoug.com:446/06031300119473114bb/2023/06/03/8f98c1d2f7c68a70353ffe79f4e103b6.zip?st=bLqh9_UcrOnTABQLUnwZLQ&e=1685771024&b=CBJbPgJjWThZX19qAyZVPQAlXXVWIgN3ATcLKFQpB2wGJA_c_c&fi=119473114&pid=124-114-128-51&up=2&mp=0&co=1";
const HomeImgUrl = "https://i51.lanzoug.com/06031300119469275bb/2023/06/03/be4b134645b515c275ffd0f23af4271d.zip?st=68AqwJVQEeQW7mBrh-cYhg&e=1685772332&b=AjgJZlA9BWVUL1Z6Bj8Ddw_c_c&fi=119469275&pid=124-114-128-51&up=2&mp=0&co=1";

const date = new Date;


//获取cookie数据
function getCookie(cookieName) {
    const strCookie = document.cookie
    const cookieList = strCookie.split(';')
    for (let i = 0; i < cookieList.length; i++) {
        const arr = cookieList[i].split('=')
        if (cookieName === arr[0].trim()) {
            return arr[1]
        }
    }
    return ''
}
//删除cookie数据
function deleteCookie(name) {
    this.setCookie(name, "", { expireDays: -1 }); //将过期时间设置为过去来删除一个cookie
}
//获取url值
function getParam(key) {
    var url = window.location.href;
    var params = url.split('?')[1];
    if (params===undefined) return null;//地址无参
    console.log(params);
    var param = params.split('&');
    for(var i = 0; i < param.length; ++i) {
        var paramKeys = param[i].split('=');
        var paramKey = paramKeys[0];
        if(key===paramKey) {
            var value = '';
            for(var j = 1; j < paramKeys.length; ++j) {
                if(paramKeys[j]==='') value+='=';
                else value+=paramKeys[j];
            }
            return value;
        }
    }
    return;
}

class Code {
    /**
     * <h2>登录被挤掉</h2>
     */
    static ACCOUNT_LOGGED_IN_NOT = 2002;
    /**
     * <h2>密码格式错误</h2>
     */
    static PASSWORD_FORMAT_NO = 2010;
    /**
     * <h2>电子邮箱已注册</h2>
     */
    static EMAIL_ALREADY_EXISTS = 2020;
}

const TopParent = {
    mounted() {
        document.title = TITLE+VERSION;//设置网页标题
        this.init();
    },
    methods: {
        sendCaptcha(prefix, email) {
            this.sendCaptchaBtnDis = true;//禁用
            var _this = this;
            axios.post(ParentUrl+"/LogIn/"+prefix+","+email).then(resp=>{
                _this.Result = resp.data;
                if (_this.Result.code===1) {
                    var x = 60;
                    var timeOutId = setInterval(function (){
                        _this.sendCaptchaBtnValue = x+'s';
                        x--;
                        if (x === 0) {
                            _this.sendCaptchaBtnValue = '发送验证码';
                            _this.sendCaptchaBtnDis = false;//解禁
                            clearInterval(timeOutId);
                        }
                    },1000);
                    this.$message({
                        message: '验证码已发送，请注意查看。',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: '电子邮箱不存在或者有误，请重新输入！',
                        type: 'warning'
                    });
                    this.sendCaptchaBtnDis = false;//解禁
                }
            }).catch(resp=>{
                this.$message({
                    message: '电子邮箱不存在或者有误，请重新输入！',
                    type: 'warning'
                });
                this.sendCaptchaBtnDis = false;//解禁
            });
        },//发送验证码
        insertUser(friendAccount) {
            var _this = this;
            axios.post(ParentUrl+"/FriendList/"+friendAccount).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    this.$message({
                        showClose: true,
                        message: '好友添加成功！',
                        type: 'success'
                    });
                    this.selectAllFriend();
                } else {
                    this.$message({
                        showClose: true,
                        message: '好友添加失败！',
                        type: 'warning'
                    });
                }
            })
        },//添加用户
        insertFriend(friendAccount) {
            var username = "";
            //先提前查询该好友是否存在并且其信息
            var _this = this;
            axios.get(ParentUrl+"/User/"+friendAccount).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    //可以查到这个用户，提示是否添加
                    username = _this.Result.data.username;
                    this.$confirm('名称：'+username, '确认添加该好友？', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //确认添加
                        this.insertUser(friendAccount);
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消添加'
                        });
                    });
                } else {
                    this.$message({
                        type: 'info',
                        message: '该用户不存在！'
                    });
                }
            });
        },//添加好友
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    done();
                })
                .catch(_ => {});
        },//是否关闭对话框
        handleClick(tab, event) {
            console.log(tab, event);
        },//登录对话框切换登陆注册页面后调用
        href(url) {
            window.location.href=ParentUrl+url;
        },
        open(url) {
            window.open(ParentUrl+url);
        }
    },
    data() {
        return {
            TITLE: "New VQ",
            VERSION: "0.12.80",
            Result: {
                code: '',//错误码
                data: '',//数据
                msg: ''//消息
            }//服务器响应标准格式
        };
    }
}